<?php 
namespace app\admin\controller;

// use think\Controller;;
use think\Db;

	class ChangeorderController 
	{

			function change_order_status(){
				// var_dump($_POST);
				// exit;
				
					$wheret['end_time']=array('lt',date("Y-m-d H:i:s"));
					$list=db('spaceOrder')->where($wheret)->where(array('lease_status'=>0))->order('create_time asc')->field('id')->limit(5)->select();
					//var_dump($list);		
					foreach ($list as $key => $value) {
						db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'lease_status'=>2));
					}



                    $list=Db::name('spaceOrder')->order('create_time asc')->field('id')->limit(5)->select();
					$now_time=date('Y-m-d');
		//var_dump($where);
					foreach ($list as $key => $value) {


						// $result=db('rent')->field('cycle_time')->where(array('order_id'=>$value['id'],'status'=>2))->find();

						// if($result){
						// 	$rent_time=explode('---', $result['cycle_time']);
						// 	if($now_time>=$rent_time[0] && $now_time <= $rent_time[1]){
						// 		db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'current_price_status'=>1));
						// 	}else{
						// 		db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'current_price_status'=>0));
						// 	}
						// }else{

						// }
						$result=db('rent')->field('cycle_time')->where(array('order_id'=>$value['id'],'status'=>2))->find();
						// if(!$result){
						// 	$results=db('rent')->field('cycle_time')->where(array('order_id'=>$value['id']))->order('id desc')->find();
						// }

						if($result){
							$rent_time=explode('---', $result['cycle_time']);
							if($now_time>=$rent_time[0] && $now_time <= $rent_time[1]){
								db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'current_price_status'=>1));
							}else{
								db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'current_price_status'=>0));
							}
						}else{

							db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'current_price_status'=>0));

						}
					}	
		    }














// */1 * * * *  curl -i  http://erp.crejoy.cn/admin/Changeorder/change_order_status














	}










































	?>
